package com.bw.bargain.controller;

import java.util.Arrays;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import com.bw.bargain.entity.CutRecordEntity;
import com.bw.bargain.service.CutRecordService;
import com.bw.common.utils.PageUtils;
import com.bw.common.utils.R;



/**
 * 砍价记录表

 *
 * @author Hao_YunKai
 * @email 2745578447@qq.com
 * @date 2022-03-10 19:02:50
 */
@RestController
@RequestMapping("bargain/cutrecord")
public class CutRecordController {
    @Autowired
    private CutRecordService cutRecordService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = cutRecordService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    public R info(@PathVariable("id") Long id){
		CutRecordEntity cutRecord = cutRecordService.getById(id);

        return R.ok().put("cutRecord", cutRecord);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    public R save(@RequestBody CutRecordEntity cutRecord){
		cutRecordService.save(cutRecord);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    public R update(@RequestBody CutRecordEntity cutRecord){
		cutRecordService.updateById(cutRecord);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    public R delete(@RequestBody Long[] ids){
		cutRecordService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

    /*
     * 朋友进行砍价
     */
    @RequestMapping("doBargainInvitation")
    public String doBargainInvitation(@RequestParam("bargainId")String bargainId,
                                      @RequestParam("userId")Long userId) {
        return "127.0.0.1:5500/doBargainInvitation.html?bargainId=" + bargainId + "&userId=" + userId;
    }

}
